﻿using _测试EF.Model;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace _测试
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }

        public void frmLoad()
        {
            using (var db = new BaseContext())
            {
                var list = from a in (
    (from StuFraction in db.StuFraction
     group StuFraction by new
     {
         StuFraction.StuId,
         StuFraction.ExamTime
     } into g
     select new
     {
         g.Key.StuId,
         g.Key.ExamTime,
         Yuw = (int?)g.Max(p => (p.CourseName == "语文" ? p.Score : 0)),
         Shux = (int?)g.Max(p => (p.CourseName == "数学" ? p.Score : 0)),
         Yingy = (int?)g.Max(p => (p.CourseName == "英语" ? p.Score : 0)),
         Lis = (int?)g.Max(p => (p.CourseName == "历史" ? p.Score : 0)),
         Dil = (int?)g.Max(p => (p.CourseName == "地理" ? p.Score : 0)),
         Wul = (int?)g.Max(p => (p.CourseName == "物理" ? p.Score : 0)),
         Huax = (int?)g.Max(p => (p.CourseName == "化学" ? p.Score : 0))
     }))
                           orderby
                             a.StuId
                           select new
                           {
                               Name =
                               ((from Student in db.Student
                                 where
        Student.Id == Convert.ToInt32(a.StuId)
                                 select new
                                 {
                                     Student.Name
                                 }).First().Name),
                               a.StuId,
                               a.ExamTime,
                               a.Yuw,
                               a.Shux,
                               a.Yingy,
                               a.Lis,
                               a.Dil,
                               a.Wul,
                               a.Huax
                           };
            }
        }
    }
}
